export class Timer{
    //完成后的回调
    public callback:Function | null = null;
    //消逝的时间
    private _elapsedTime:number  = 0;

    //步长，时间以秒为单位
    private _setp:number = -1;
    get elapsedTime():number{
        return this._elapsedTime;
    }

    set setp(setp:number){
        this._setp = setp;
    }

    get progerss():number{
        return this._elapsedTime / this._setp;
    }

    constructor(setp:number = 0){
        this._setp = setp;
    }

    public update(deltaTime:number){
        if (this.setp <=0 ) return false;
        this._elapsedTime += deltaTime;
        if (this._elapsedTime >= this._setp) {
            this._elapsedTime -= this._setp;
            this.callback?.call(this)
            return true;
        }
    }

    public reset():void{
        this._elapsedTime = 0;
    }
    public stop():void{
        this._elapsedTime = 0;
        this._setp = -1;
    }


}